/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

/**
 *
 * @author Thommie
 */
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ImagePanel extends JPanel{

    private URL url = null;   
    private Image uImg;
    boolean clear;

    public ImagePanel() {
        clear=false;
    }

    

    public void updateImage(String u){
        this.setBorder(BorderFactory.createEmptyBorder(44, 44, 44, 44));//  sätter tomt fält runt panel.
        try {
            clear=true;
            repaint();
            clear = false;
            url = new URL(u);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        uImg = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage(url);
         repaint();
    }

    
    

    public void paintComponent(Graphics g) {
        if(clear){
            

        }else{
           // g.drawImage(uImg, 0, 0, this); // see javadoc for more info on the parameters
       // g.drawOval(44, 44, 44, 44);
            g.drawImage(uImg, 0, 0, 200, 300, this);
        }
        

    }

}